home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / cross / ava-0.2.5.lha / ava-0.2.5 / src / Lexer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-23  |  1.5 KB  |  58 lines

  1. /* Lexer.h */
  2.  
  3. #ifndef __Lexer
  4. #define __Lexer
  5.  
  6. #include <assert.h>
  7.  
  8. #define LX_STRLEN    128
  9. #define LX_LINEBUF    512
  10.  
  11. #define GET_TOKEN    lexer.gettoken()
  12. #define PUT_TOKENBACK    lexer.getback();
  13. #define WHILE_TOKEN    while(lexer.gettoken())
  14.  
  15. struct TlxData{
  16.   enum TlxType{THEEND=0,STRING=1,QSTRING=2,LVAL=3,PREPROC=4, 
  17.                CONTROL=5,MATH=6,NEWLINE=7,LABEL=8};
  18.   char string[LX_STRLEN];
  19.   long lval;
  20.   TlxType type;
  21.   char buf;        /* character buffer */
  22.   int back_count;    /* If token is returned back, increment this counter,
  23.                            that next time gettoken function is invoked, the
  24.                same string will be returned. */
  25.   bool stick;        /* if current token is placed just by the last one,
  26.                            this variable become true */
  27.   bool macro;        /*if string was replaced by macro, set this flag high*/
  28.   long lastCurPos;      /* last cursor position */
  29. };
  30.  
  31. /* global structure */
  32. extern TlxData lxdata;
  33. extern TlxData *lxP;
  34.  
  35. class TLexer{
  36. private:
  37.   void getnext();
  38. public:  
  39.   TLexer();
  40.   ~TLexer(){}
  41.   int __gettoken();    /* pure tokens */  
  42.   int _gettoken();    /* without remarks */
  43.   /* gettoken cooperates with symbols, macros and remarks
  44.      returns TlxData::THEEND if eof is reached otherwise lxdata is updated. */
  45.   int gettoken();  
  46.   void getback(){assert(lxdata.back_count<1);lxdata.back_count++;}  
  47.   
  48.   /* flush current buffer: current character in buffer is pushed back 
  49.      to owner and afterthat, it is cleared - prepeared for new stream. */
  50.   void flush();
  51.   void Unroll();
  52. };
  53.  
  54. extern TLexer lexer;
  55.  
  56. #endif
  57.  
  58.